﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Globalization;
using Vowei.Core;
using Vowei.Web;
using Vowei.Core.Models;

namespace vowei.test
{
    [TestClass]
    public class GlobLocTest
    {
        [TestMethod]
        public void GlobInterfaceTest()
        {
            var culture = new CultureInfo("zh-cn");
            var translator = new Translator(culture);
            Assert.AreEqual("标题", translator.T("标题"));
            
            culture = new CultureInfo("en-us");
            translator = new Translator(culture);

            var date = DateTime.Now;
            Assert.AreEqual(date.ToString(culture), translator.T(date));

            var percentage = 0.7;
            Assert.AreEqual(percentage.ToString(culture), translator.T(percentage));

            // 只是演示一个概念。
            // Assert.AreEqual("title", translator.T("标题"));
        }

        class TestWebViewPage<T> : G18nWebViewPage<T>
        {
            public TestWebViewPage()
            {
                Translator = new Translator(new CultureInfo("zh-cn"));
            }

            public override void Execute()
            {
                throw new NotImplementedException();
            }
        }

        [TestMethod]
        public void GetPropertyLocalizedNameTest()
        {
            var page1 = new TestWebViewPage<Milestone>();
            Assert.AreEqual("标题", page1.T(m => m.Title));

            var page2 = new TestWebViewPage<Ticket>();
            Assert.AreEqual("开始日期", page2.T(m => m.BelongsToMilestone.StartDate));

            var page3 = new TestWebViewPage<IEnumerable<Ticket>>();
            Assert.AreEqual("开始日期", page3.T(m => m.First().BelongsToMilestone.StartDate));
        }        
    }
}
